using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using Ksibo.Modelo;
using NHibernate.Expression;

namespace Ksibo.Negocio
{
    public static class Autentica
    {
        
        
        public static Usuario existeUsuario(string login, string senha) {
            Usuario us = new Usuario();

            Configuration cfg = new Configuration();
            cfg.AddAssembly("Ksibo");
            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            
            ITransaction tx = session.BeginTransaction();

            ICriteria crit = session.CreateCriteria(typeof(Usuario));
            crit.Add(Expression.Eq("Login", login));
            crit.Add(Expression.Eq("Senha", senha));
            us = (Usuario)crit.UniqueResult();
            tx.Commit();

            session.Close();

            return us;
        }
    }
}
